package com.yudean.esb.cached;

import com.yudean.esb.domain.esb.EsbServiceConfig;

import java.util.HashMap;
import java.util.Map;

/**
 * 有关自定义服务的配置集合
 *
 * @author : DL<duanlei@gdyd.com>
 * @version : 1.0
 */
public class ServicesCollection {
    private static ServicesCollection ourInstance = new ServicesCollection();
    private static Map<String, EsbServiceConfig> serviceList;
    //key = tbcolName ,value = nodeName
    private static Map<String, Map<String, String>> mapper;

    static {
        serviceList = new HashMap<String, EsbServiceConfig>();
        mapper = new HashMap<String, Map<String, String>>();
    }

    private ServicesCollection() {
    }

    public static ServicesCollection getInstance() {
        return ourInstance;
    }

    /**
     * 添加Service配置，如果有，则覆盖掉
     *
     * @param serviceID
     * @param config
     */
    public static void putService(String serviceID, EsbServiceConfig config) {
        if (config == null) {
            return;
        }
        serviceList.put(serviceID, config);
    }

    /**
     * 根据ServiceID获得service的配置信息
     *
     * @param serviceID
     * @return
     */
    public static EsbServiceConfig getService(String serviceID) {
        return serviceList.get(serviceID);
    }

    /**
     * 刪除服務
     *
     * @param serviceID
     */
    public static void removeSerive(String serviceID) {
        serviceList.remove(serviceID);
    }

    /**
     * 添加服务的自定义映射
     *
     * @param serviceID
     * @param map
     */
    public static void putMapper(String serviceID, Map<String, String> map) {
        if (map == null) return;
        mapper.put(serviceID, map);
    }

    /**
     * 根据服务ID获取映射关系
     *
     * @param serviceID
     * @return
     */
    public static Map<String, String> getMapper(String serviceID) {
        if (serviceID == null || "".equals(serviceID)) return null;
        return mapper.get(serviceID);
    }

    /**
     * 刪除映射
     *
     * @param serviceID
     */
    public static void removeMapper(String serviceID) {
        mapper.remove(serviceID);
    }
}